//
//  BBThreePicCell.swift
//  BaoKanSwift
//
//  Created by uncle-R on 16/6/13.
//  Copyright © 2016年 uncle-R. All rights reserved.
//

import UIKit


class BBThreePicCell: UITableViewCell {

    @IBOutlet weak var looked: UILabel!
    @IBOutlet weak var comment: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var image3: UIImageView!
    @IBOutlet weak var image2: UIImageView!
    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var image1: UIImageView!
    
    var model :BBNewsModel?{
        didSet{
            
            if model!.morepic?.count == 1 {
                self.image1.image = nil
                self.image1.sd_setImageWithURL(NSURL(string: model!.morepic![0]), placeholderImage: UIImage(named: "placeholder_logo.png"))
            }else if model!.morepic?.count == 2{
                self.image1.image = nil
                self.image2.image = nil
                self.image1.sd_setImageWithURL(NSURL(string: model!.morepic![0]), placeholderImage: UIImage(named: "placeholder_logo.png"))
                self.image2.sd_setImageWithURL(NSURL(string: model!.morepic![1]), placeholderImage: UIImage(named: "placeholder_logo.png"))
                
            }else if model!.morepic?.count == 3{
                self.image1.image = nil
                self.image2.image = nil
                self.image3.image = nil
                self.image1.sd_setImageWithURL(NSURL(string: model!.morepic![0]), placeholderImage: UIImage(named: "placeholder_logo.png"))
                self.image2.sd_setImageWithURL(NSURL(string: model!.morepic![1]), placeholderImage: UIImage(named: "placeholder_logo.png"))
                self.image3.sd_setImageWithURL(NSURL(string: model!.morepic![2]), placeholderImage: UIImage(named: "placeholder_logo.png"))
            }
            self.title.text = model!.title  ?? ""
            self.time.text = model!.newstime ?? ""
            self.comment.text = model!.plnum ?? ""
            self.looked.text = model!.onclick ?? ""
        }
    }
    
    func getRowHeight(model: BBNewsModel) -> CGFloat {
        self.model = model
        layoutIfNeeded() //更新约束
        print("y = \(CGRectGetMaxY(title.frame))--\(CGRectGetMaxY(image1.frame))---\(CGRectGetMaxY(time.frame))")
        model.rowHeight = CGRectGetMaxY(time.frame) + 15
        print(model.rowHeight)
        return model.rowHeight
    }
    //y = 36.0--133.0---163.0
    override func awakeFromNib() {
        super.awakeFromNib()
         selectionStyle = UITableViewCellSelectionStyle.None
    }

  
}
